package com.more.offer.threadtest.forkjoin;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;

/**
 * @author yinpeng10
 * @desc
 */
public class CountTaskMain {

	public static void main(String[] args) throws ExecutionException, InterruptedException {
		long startTime = System.currentTimeMillis();
		ForkJoinPool forkJoinPool = new ForkJoinPool();
		ForkJoinTask<Integer> submit = forkJoinPool.submit(new CountTask(1, 100));
		if(submit.isCompletedAbnormally()) {
			System.out.println("累加发生错误: " + submit.getException());
		}
		System.out.println("1+...100=" + submit.get());
		System.out.println("total time: " + (System.currentTimeMillis() - startTime));

		useAdd();
	}
	public static void useAdd(){
		long startTime2 = System.currentTimeMillis();
		int count = 0;
		for (int i = 1; i <= 1000; i++) {
			count+=i;
		}
		System.out.println(count);
		System.out.println("total time: " + (System.currentTimeMillis() - startTime2));
	}
}
